package  com.uw.scenic.controller;



import com.uw.scenic.entity.User;
import com.uw.scenic.service.UserService;


import com.uw.scenic.common.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;

/**
 * Title:  UserController
 * Description: 请填写描述信息
 * @author   yls
 * @created  2023年12月20日 08:56:41 星期三
 */
@Slf4j
@Api(value = "UserController", tags = "请填写描述信息")
@RestController
@RequestMapping(value = "/user", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})
public class UserController {

    @Autowired
    private UserService userService;



    /**
     * 详情
     * @param id
     * @return
     */
    @ApiOperation(value = "获取详情",notes = "获取详情",httpMethod = "GET")
    @GetMapping(value = "/detail")
    public  ResponseResult  detail(@RequestParam(value = "id",required = true) Long id){
        return    userService.detail(id);
    }




    /**
     * 列表
     * @return
     */
    @ApiOperation(value = "列表",notes = "列表接口",httpMethod = "GET")
    @GetMapping(value = "/list")
    public  ResponseResult  list(){
        return   userService.getList();
    }



     /* 列表-分页
     * @param request
     * @param pageNumber 当前页
     * @param pageSize   每页显示记录数
     * @return
     */
    @ApiOperation(value = "分页查询接口",notes = "分页查询接口",httpMethod = "GET")
    @GetMapping(value = "/pageList")
    public  ResponseResult  pageList(@RequestParam(value = "pageNumber",required = false,defaultValue = "1") Integer pageNumber,
                             @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize,
                             HttpServletRequest request){
        if (pageNumber == null) {
            pageNumber = 1;
        }

        if (pageSize == null) {
            pageSize = 10;
        }
        return  userService.getPageList(pageNumber,pageSize);
    }



   /**
     * 新增操作
     * @param request
     * @param
     * @return
     */
    @ApiOperation(value = "保存接口",notes = "保存接口",httpMethod = "POST")
    @PostMapping(value = "/save")
    public  ResponseResult  save(User  user, HttpServletRequest request){
       return userService.saveData(user);
    }




    /**
     * 更新操作
     * @param request
     * @return
     */
    @ApiOperation(value = "更新接口",notes = "更新接口",httpMethod = "POST")
    @PostMapping(value = "/update")
    public  ResponseResult   update(User  user, HttpServletRequest request){
        return    userService.update(user);
    }






    /**
     * 删除操作
     * @return
     */
    @ApiOperation(value = "删除接口",notes = "删除接口",httpMethod = "POST")
    @PostMapping(value = "/delete")
    public  ResponseResult  deleteById(@RequestParam(value = "id",required = true) Long id){
        return   userService.deleteById(id);
    }

}